import java.util.regex.Pattern;

public class db_statement_create_database implements db_interface_statement {

	public String[] oTokens = new String[2];
	public Pattern[] oRegex = new Pattern[1];
	private db_util_parser oUtilParser = null;
	db_parse_result_create_database oRes = null;

	db_statement_create_database() {
		oTokens[0] = "CREATE";
		oTokens[1] = "DATABASE";

		oRegex[0] = Pattern.compile("[a-zA-Z][0-9a-zA-Z]*");

		oUtilParser = new db_util_parser(oTokens);
	}
	public db_interface_parse_result parse(String sSQL) {
		oRes =  new db_parse_result_create_database();
		oUtilParser.restart(sSQL);
		int iRes = query();

		if (oUtilParser.sQuery.trim().length() > 0 && iRes == 0)
			iRes = -1;

		oRes.set_result(iRes);
		return oRes;
	}

	public int query() {
		if (!oUtilParser.matchReplace(oUtilParser.sQuery, oTokens[0]))
			return -2;
		if (!oUtilParser.matchReplace(oUtilParser.sQuery, oTokens[1]))
			return -2;
		if (!oUtilParser.matchReplace(oUtilParser.sQuery, oRegex[0]))
			return -1;
		oRes.sDBName = oUtilParser.sValue;
		return 0;
	}
}
